package ali;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

/**
 * @author zky
 */
public class Test02 {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String s = bf.readLine();
        String[] split = s.substring(1, s.length()-1).split(",");
        int[] num = new int[split.length];
        for (int i = 0; i < split.length; i++) {
            num[i] = Integer.parseInt(split[i]);
        }
        int n = Integer.parseInt(bf.readLine());
        System.out.println(get(n, num));

    }

    public static int get(int k,int[] num){
        if(num == null|| num.length == 0){
            return 0;
        }
        int i = 0;
        int res = 0;
        while(i<num.length){
            for (int j = 0; j < num.length; j++) {
                if(num[j] == 1){
                    i++;
                }else {
                    if(i+k<num.length) {
                        for (int l = i; l < i+k; l++) {
                            num[l] = num[l] == 0? 1:0;
                        }
                        res++;
                    }else {
                        for (int l = i; l < num.length; l++) {
                            if(num[l] == 0){
                                return -1;
                            }
                        }
                        return res;
                    }
                }
            }
        }
        return res;
    }
}
